﻿@using System.Collections
@using System.Reflection
@using Sharp.DataTransferObject
@using Sharp.Portal.Mvc.Bootstrap
@model IList<Sharp.DataTransferObject.OAuthConfigDTO>
@if (ViewBag.IsPjaxRequest == false)
{
    Layout = "../Shared/__Layout.cshtml";
}
<section class="content-header">
    <h1>
        快捷登录
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a></li>
        <li class="active">用户</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">

                <div class="box-body no-padding">
                    <div class="table-responsive">
                        <table id="oAuthDataTable" class="table table-bordered table-striped table-hover dataTable text-center">
                            <thead>
                                <tr>
                                    <th>OAuth平台</th>
                                    <th>AppId</th>
                                    <th>AppSecret</th>
                                    <th>可用</th>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    var arrays = Enum.GetValues(typeof(OAuthConfigDTO.OAuthType));
                                    int i = 0;
                                    foreach (OAuthConfigDTO.OAuthType config in arrays)
                                    {
                                        if (config == OAuthConfigDTO.OAuthType.None)
                                        {
                                            continue;
                                        }
                                        var data = Model.FirstOrDefault(x => x.Interface == config);
                                        if (data == null)
                                        {
                                            data = new OAuthConfigDTO() { Interface = config, IsEnable = true };
                                        }
                                        <tr>
                                            <td>@config.GetDescription()</td>
                                            <td class="text-center"><input type="text" value="@data.AppId" name="oauthData[@i].appId" style="width: 200px" class="form-control"></td>
                                            <td class="text-center"><input type="text" value="@data.AppSecret" name="oauthData[@i].AppSecret" style="width: 300px" class="form-control"></td>
                                            <td>
                                               <input type="checkbox" name="oauthData[@i].isEnable" value="true" @(data.IsEnable?"checked":"") >
                                             
                                                <input type="hidden" name="oauthData[@i].Interface" value="@((int)data.Interface)" />
                                                <input type="hidden" name="oauthData[@i].id" value="@data.Id" />
                                            </td>
                                        </tr>

                                        i++;
                                    }
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="modal-footer">
        @Html.Bootstrap().Button("保存", "btnSave").Style(BootstrapStyle.Primary)
    </div>
</section>
<script type="text/javascript">
    $('#oAuthDataTable').DataTable( {
        responsive: true
    } );
    $('#btnSave').click(function() {
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save")',
                data: $(".dataTable").find("input").serialize(),
                dataType: "json",
                success: function(data) {
                    if (data.errors.length > 0) {
                        swal("出错啦！", data.errors, "error");
                    } else {
                        swal("已经保存", "保存成功！", "success");
                    }
                }
            });
    });
 

</script>